home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!txwang
- From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
- Newsgroups: comp.lang.c++
- Subject: Re: int::~int()
- Date: Tue, 16 Apr 1996 01:00:25 GMT
- Message-ID: <199604160100.KAA06143@public1.guangzhou.gd.cn>
- X-NNTP-Posting-Host: txwang
- X-Newsreader: Forte Free Agent 1.0.82
- X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
-
- On Sun, 14 Apr 1996 13:49:59 +0900, Xu Yifeng <jafd@public.sta.net.cn>
- wrote:
-
- | Hi everybody,
-
- | can your compiler compile following program?
-
- | //------------------------
- | void main()
- | {
- | int i = 0;
-
- | i.int::~int();
- | }
- | //------------------------
-
- | is it a legal C++ program?
-
- Though many guys had said it is a legal one, I don't think it's a
- meaningful one. The Sep, 95 draft Standard says in 12.4:
-
- 12 Invocation of destructors is subject to the usual rules for
- member functions (_class.mfct_), e.g., an object of the
- appropriate type is required (except invoking delete on a
- null pointer has no effect). Once a destructor is invoked for an
- object, the object no longer exists; the behavior is
- undefined if the destructor is invoked for an object whose
- lifetime has ended (_basic.life_). [Example: if the
- destructor for an automatic object is explicitly invoked,
- and the block is subsequently left in a manner that would
- ordinarily invoke implicit destruction of the object, the
- behavior is undefined. ]
-
- The [Example:...], though it isn't part of the standard, says
- something directly related to your program.
-
- Although there're some differences between "well-formed program" and
- "undefined behavior", I don't think it's a bad idea that a compiler
- rejects this sort of code, as it will surely cause undefined
- behaviors.
-
- The plain old Borland C++ 3.1 compiles
-
- int i = 0;
- (&i)->int::~int();
-
- just fine. And that's the "Standard" way(via pointer) to explicitly
- call a destructor.
-
-
- ---
- Wang TianXing
-
-
-